﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Quanlynhansu
{
    public partial class frmDangnhap : Form
    {
        public frmDangnhap( )
        {
          
            InitializeComponent();
        }
        public SqlConnection getConnect()
        {
            return new SqlConnection(@"Data Source=HaTuan\HATUAN;Initial Catalog=QLNS;Integrated Security=True");
        }
        public DataTable CheckLogin(string user, string pass)
        {
            string sql = "Select * from Dangnhap where Tendangnhap ='" + user + "'and Matkhau ='" + pass + "'";
            SqlConnection con = getConnect();
            SqlDataAdapter adap = new SqlDataAdapter(sql, con);
            DataTable dt = new DataTable();
            adap.Fill(dt);
            return dt;
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = CheckLogin(txtUser.Text, txtPass.Text);
            if (dt.Rows.Count > 0)
            {
                this.Hide();
                Form1 frmMain = new Form1();
                frmMain.ShowDialog();
                this.Close();
            }
            else
            { 
                lbstt.Text = "Đăng nhập sai!";
            }
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
